const App = getApp();
Page({
    data: {
        imgUrl:App.globalData.imgUrl,
        isLoading: true,
        reLoading: false,
        list: [],
    },
    onLoad: function (options) {
        let _this = this;
        _this.getCardList();
    },

    // 获取卡密记录
    getCardList(page = 1) {
        let _this = this;
        App._get('card/lists', {page}, res => {
            _this.setData({
                list: _this.data.list.concat(res.data.list.data),
                current_page: res.data.list.current_page,
                last_page: res.data.list.last_page,
                total: res.data.list.total,
            })
        }, false, () => {
            _this.setData({
                isLoading: false,
                reLoading: false,
            })
        })
    },

    copy(e) {
        let _this = this;
        wx.setClipboardData({
            data: e.currentTarget.dataset.text,
            success: function (res) {
                wx.getClipboardData({
                    success: function (res) {
                        wx.showToast({
                            title: '复制卡密成功'
                        })
                    }
                })
            }
        })
    },

    toDetail(e) {
        let _this = this;
        let item = e.currentTarget.dataset.item;
        wx.navigateTo({
            url: './detail?card_id=' + item.card_id
        })
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        this.ajaxloading = this.selectComponent("#ajax_loading");
        if (this.data.current_page >= this.data.last_page) {
            this.ajaxloading.AjaxLoading(true);
            this.ajaxloading.AjaxNoresult(false);
            return false;
        }
        this.getCardList(this.data.current_page + 1);
        this.ajaxloading.AjaxLoading(false);
    },


});
